﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UIShare;
using EFong.View.Proxy;

namespace EFong.View.Financing
{
    public partial class Frm_TouringPartySettlement : BasicMdiChildForm
    {
        private Proxy.MasterServiceProxy _masterProxy {get{ return Proxy.MasterServiceProxy.GetInstance();}}
        private Proxy.FinanceServiceProxy _financeProxy {get{ return Proxy.FinanceServiceProxy.GetInstance();}}

        public Frm_TouringPartySettlement()
        {
            InitializeComponent();
        }

        protected override void InitFields()
        {
            base.InitFields();
        }

        protected override void Events()
        {
            base.Events();

            this.gv_TouringPartySettlements.FocusedRowChanged += (s, e) =>
                {
                    Settlement = this.gv_TouringPartySettlements.GetRow(e.FocusedRowHandle) as Contract.TourPartySettlement;
                };
        }

        protected override void LoadDatas()
        {
            base.LoadDatas();
            bds_TouringParty.BindingData(_financeProxy.GetPendingPayTouringParty().ReturnValue);
        }

        private void bar_Main_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            switch (e.Item.Name)
            {
                case "bbt_Save":
                    this.payTouringParty();
                    break;
                case "bbt_Close":
                    this.Close();
                    break;
                default:
                    break;
            }
        }

        private void payTouringParty()
        {
            if (Settlement == null)
                return;

            Frm_TouringPartySettlementEdit frm = new Frm_TouringPartySettlementEdit();
            frm.Text = "自组团支付";
            frm.Settlement = Settlement;
            if (FormOpener.ShowDialog(frm) == DialogResult.OK)
            {
                this.gv_TouringPartySettlements.BeginDataUpdate();
                bds_TouringParty.BindingData(_financeProxy.GetPendingPayTouringParty().ReturnValue);
                this.gv_TouringPartySettlements.EndDataUpdate();
            }
        }

        public Contract.TourPartySettlement Settlement { get; set; }
    }
}
